<form autocomplete="off" class="layui-form layui-box modal-form-box" action="{:request()->url()}" data-auto="true" method="post">

    <div class="layui-form-item">
        <label class="layui-form-label">名称（标题）</label>
        <div class="layui-input-block">
            <input autofocus name="name" value='{$vo.name|default=""}' required title="请输入" placeholder="请输入，如出发城市" class="layui-input" onblur="this.value=this.value.trim()">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">可选值</label>
        <div class="layui-input-block">
            <div class="param-table-list">
                <table class="layui-table margin-none">
                    <tbody class="param-table-list">
                    {if !empty($vo['value'])}
                    {foreach $vo['value'] as $v}
                    <tr class="transition">
                        <td class="param-input-td one nowrap" style="padding: 0px;">
                            <input name="value[]" value="{$v}" required placeholder="请输入" title="请输入" class="layui-input" onblur="this.value=this.value.trim()">
                        </td>
                        <td class="param-input-td thr nowrap text-center">
                            <a class="color-desc del">删除</a>
                            <a class="color-desc up">上移</a>
                            <a class="color-desc down">下移</a>
                        </td>
                    </tr>
                    {/foreach}
                    {else}
                    <tr class="transition">
                        <td class="param-input-td one nowrap" style="padding: 0px;">
                            <input name="value[]" required placeholder="请输入" title="请输入" class="layui-input" onblur="this.value=this.value.trim()">
                        </td>
                        <td class="param-input-td thr nowrap text-center">
                            <a class="color-desc del">删除</a>
                            <a class="color-desc up">上移</a>
                            <a class="color-desc down">下移</a>
                        </td>
                    </tr>
                    {/if}
                    </tbody>
                </table>
            </div>
            <table class="layui-table">
                <tr>
                    <td class="text-center notselect padding-none border-none">
                        <button type="button" class="layui-btn full-width layui-btn-primary add">添加属性</button>
                    </td>
                </tr>
            </table>
        </div>

    </div>



    {if isset($vo['id'])}
    <input type='hidden' value='{$vo.id}' name='id'/>
    {else}
    <input type="hidden" value="{:date('Y-m-d H:i:s')}" name="create_at">
    {/if}

    <div class="hr-line-dashed"></div>

    <div class="layui-form-item text-center">
        <button class="layui-btn" type='submit'>保存数据</button>
    </div>
</form>
<style>
    .param-table-list {
        overflow: auto;
        max-height: 200px;
        position: relative;
        overflow-y: scroll;
    }

    .param-input-td {
        position: relative;
        padding: 0 !important;
    }

    .param-input-td.one {
        width: 30%;
    }

    .param-input-td.thr {
        width: 20%;
        text-align: center;
    }

    .param-input-td.one:before {
        content: '可选值'
    }

    .param-input-td.two:before {
        content: '链接'
    }

    .param-input-td:before {
        margin: 4px;
        width: 40px;
        height: 30px;
        line-height: 30px;
        text-align: center;
        position: absolute;
        background: #e2e2e2;
    }

    .param-input-td input {
        padding-left: 50px;
        border: none !important;
    }
</style>

<script>
    $('.add').on('click',function () {
        var html_str = `<tr class="transition">
                        <td class="param-input-td one nowrap" style="padding: 0px;">
                            <input name="value[]" required placeholder="请输入" title="请输入" class="layui-input" onblur="this.value=this.value.trim()">
                        </td>
                        <td class="param-input-td thr nowrap text-center">
                            <a class="color-desc del">删除</a>
                            <a class="color-desc up">上移</a>
                            <a class="color-desc down">下移</a>
                        </td>
                    </tr>`;
        $('tbody.param-table-list').append(html_str);
    })

    $('tbody.param-table-list').on('click','.del',function () {
        $(this).parents('.transition').remove();
    })

    $('tbody.param-table-list').on('click','.up',function () {
        var parentsDiv = $(this).parents(".transition");
        var prev = parentsDiv.prev();
        if(prev.html()!=undefined){
            //prev.before(parentsDiv);
            prev.fadeOut("fast",function(){
                $(this).before(parentsDiv);
            }).fadeIn();
        }
    })

    $('tbody.param-table-list').on('click','.down',function () {
        var parentsDiv = $(this).parents(".transition");
        var next = parentsDiv.next();
        if(next.html()!=undefined){
            //next.after(parentsDiv);
            next.fadeOut("fast",function(){
                $(this).after(parentsDiv);
            }).fadeIn();
        }
    })
</script>
